/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.ability.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

import com.xuexiang.xui_lib.util.Log;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.ability.EasyIndicatorSliceAbility;
import com.xuexiang.xuidemo.slice.tabbar.EasyIndicatorSlice;
import com.xuexiang.xuidemo.slice.tabbar.JPTabBarSlice;
import com.xuexiang.xuidemo.slice.tabbar.TabControlViewSlice;
import com.xuexiang.xuidemo.slice.tabbar.VerticalTabLayoutSlice;
import com.xuexiang.xuidemo.slice.tabbar.tabsegment.TabSegmentSlice;


public class TabBarAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private static final String TAG = "TabBarAbilitySlice";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        Log.d(TAG,"onStart : ");
        super.setUIContent(ResourceTable.Layout_ability_tab_bar);
        findComponentById(ResourceTable.Id_tab_bar_EasyIndicator_btn).setClickedListener(this);
        findComponentById(ResourceTable.Id_tab_bar_backImage).setClickedListener(this);
        findComponentById(ResourceTable.Id_tab_bar_vertical_tabLayout).setClickedListener(this);
        findComponentById(ResourceTable.Id_tab_bar_TabControlView_btn).setClickedListener(this);
        findComponentById(ResourceTable.Id_tab_bar_tabsegment).setClickedListener(this);
        findComponentById(ResourceTable.Id_jpt_layout).setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_tab_bar_EasyIndicator_btn:
                Intent newIntent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName(EasyIndicatorSliceAbility.class.getName())
                    .build();

                // 把operation设置到intent中
                newIntent.setOperation(operation);
                startAbility(newIntent);
                break;
            case ResourceTable.Id_tab_bar_tabsegment:
                present(new TabSegmentSlice(),new Intent());
                break;
            case ResourceTable.Id_tab_bar_backImage:
                terminate();
                break;
            case ResourceTable.Id_tab_bar_TabControlView_btn:
                present(new TabControlViewSlice(), new Intent());
                break;
            case ResourceTable.Id_tab_bar_vertical_tabLayout:
                present(new VerticalTabLayoutSlice(), new Intent());
                break;
            case ResourceTable.Id_jpt_layout:
                present(new JPTabBarSlice(), new Intent());
                break;
            default:
                break;
        }
    }

}
